<template>
  <div class="classification">
    <div style="margin-top: 20px;margin-bottom: 20px; padding-left: 40px;">
      <el-button type="success" @click="dialogFormVisible = true"
                  style="margin-right: 30px;"><el-icon><Plus /></el-icon>增加</el-button>
     <el-button type="danger" @click=""> <el-icon><Delete /></el-icon>批量删除</el-button>
    </div>
<!-- 对话框 -->
<el-dialog v-model="dialogFormVisible" title="添加分类"
width="400px">
    <el-form :model="form" >
      <el-form-item label="分类名称" :label-width="formLabelWidth">
        <el-input v-model="form.name" autocomplete="off" />
      </el-form-item>
      <el-form-item label="排序值" :label-width="formLabelWidth">
        <el-input v-model="form.name" autocomplete="off" />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取消</el-button>
        <el-button type="primary"  @click="dialogFormVisible = false" >
          确定
        </el-button>
      </span>
    </template>
  </el-dialog>
    <el-divider /><!-- 分割线 -->
    <!-- 分类界面 -->
    <el-table ref="<!-- multipleTableRef -->" :data="state.tableData" style="width: 100%" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="80" />
      <el-table-column label="产品分类" width="300">
        <template #default="scope">{{ scope.row.name}}</template>
      </el-table-column>
      <el-table-column property="number" label="排序值" width="220" />
      <el-table-column property="time" label="添加时间" show-overflow-tooltip />
      <el-table-column fixed="right" label="操作" width="220">
        <template #default>
          <el-button link type="primary" size="small" @click="dialogFormVisible = true">修改</el-button>
          <el-button link type="primary" size="small" @click="open">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <div class="Pagination">
      <el-pagination background layout="prev, pager, next" 
      :total="40" 
      :page-size="15"
      />
    </div>
  </div>
</template>

<script setup>
import axios from 'axios' 
import { ref,reactive,onMounted} from 'vue'
import { ElMessage, ElMessageBox } from "element-plus";
/* 对话框 */
const dialogFormVisible = ref(false)
const formLabelWidth = '140px'

const form = reactive({
  delivery: false,
  type: [],
  tableData:[]
})
/* 内容定义 */
const state = reactive({
  tableData: [], // 数据列表
})
onMounted(() => {
  getCategory()
})
const getCategory= () => {
  axios.get('http://rap2api.taobao.org/app/mock/308829/api/classification')      
.then((res) => {
console.log(res)
state.tableData = res.data.classify
//  console.log(tableData)
})
}
//删除商品
const open = () => {
  ElMessageBox.confirm("你确定要删除这个商品吗？", "商品信息", {
    confirmButtonText: "删除",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(() => {
      ElMessage({
        type: "success",
        message: "删除成功",
      });
    })
    .catch(() => {
      ElMessage({
        type: "info",
        message: "删除失败",
      });
    });
};
</script>

<style lang="less" scoped>
.Pagination {
  margin-top: 30px;
  display: flex;
  justify-content: center;
}
</style>
